FROM node:14.20-alpine as builder

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories



RUN  mkdir  -p -m 0700 ~/.ssh && echo $'Host *\n\
  StrictHostKeyChecking no\n\
  UserKnownHostsFile=/dev/null\n'\
  > ~/.ssh/config \
 && apk add --no-cache git openssh-client  && ssh-keygen -q -N " " -f ~/.ssh/id_rsa \
&& ssh-keyscan gitlab.com >> ~/.ssh/known_hosts

COPY ./git-key/id_rsa.pub   /tmp/
COPY ./git-key/id_rsa /tmp/


RUN  chmod 700 /tmp/id_rsa.pub && chmod 700 /tmp/id_rsa

RUN cat /tmp/id_rsa.pub > ~/.ssh/id_rsa.pub && cat /tmp/id_rsa > ~/.ssh/id_rsa

WORKDIR /opt/


RUN git init&& git remote add origin git@gitee.com:wen2020/micro-service.git&& git config core.sparsecheckout true && echo "multi-data-provider/front" >> .git/info/sparse-checkout



RUN git pull   --depth 1 --progress origin master

WORKDIR /opt/multi-data-provider/front/


#RUN npm config set registry https://registry.npmmirror.com

#RUN npm install && npm run build


RUN yarn config set registry https://registry.npmmirror.com

RUN yarn add terser-webpack-plugin@1.4.5 compression-webpack-plugin@1.1.12 &&yarn install --pure-lockfile&& yarn run build --report 


FROM nginx:alpine as nginxBuild

USER root


COPY --from=builder /opt/multi-data-provider/front/dist/ /usr/share/nginx/html/


RUN  chmod -R 777 /usr/share/nginx/html

ADD ./default.conf /etc/nginx/conf.d/default.conf
ADD ./nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

ENTRYPOINT ["nginx","-g","daemon off;"]

